package bgu.eliav;

import java.util.Vector;


final public class DataBase implements DbFunctionality {
	private static DataBase instace = null;
	private Vector<User> list= null;
	
	
	private final static Integer myMutex = new Integer(1);

	// Private constructor prevents instantiation from other classes
	private DataBase() {
		list= new Vector<User>();
	}



	public void setList(Vector<User> list) {
		this.list = list;
	}

	// what is the problem over here? how do you solve it?
	public static DataBase getInstance() {
		if (instace == null){
			synchronized(myMutex){
				if (instace == null){
					instace = new DataBase();
				}
			}
		}

		return instace;
	}

	public Vector<User> getListOfUsers() {
	return list;
	}

	public void newUser(User user) {
	list.add(user);
		
	}

	public void remove(User user) {
		
		for(int i=0;i<list.size();i++){
			if(user.getName().equals(list.elementAt(i).getName())){
				list.remove(i);
			}
		}
	}
	
}